import React, { Component } from 'react'
import { DatePicker, Space } from 'antd';
import locale from 'antd/es/date-picker/locale/zh_CN';
import {Link,withRouter} from 'react-router-dom'
import { connect } from 'react-redux';
import moment from 'moment'

const { RangePicker } = DatePicker;

class CurveDatePicker extends Component {
  constructor(props) {
    super(props);
    this.state = {  };
  }
  disabledDate = (current) => {
    return current && current > moment().subtract(1,'days')
  }
  handleOnChange = (value) => {
    // console.log();
    const { equip, choice, getCurve, getAverageRate, setEquip } = this.props;
    const start = moment(value[0]).format('YYYY-MM-DD');
    const end = moment(value[1]).format('YYYY-MM-DD')
    let curveEquip = {
      equipId: equip.equipId,
      allType: 'allType',
      choice: choice,
      startTime: start,
      endTime: end,
      positionId: equip.positionId
    }
    // setEquip({equip:curveEquip});
    console.log(choice);
    if (choice !== 4) {
      getCurve(curveEquip)
    } else {
      getAverageRate(curveEquip)
    }
  }
  render() {
    return (
      <Space  direction="vertical" size={12} style={{marginLeft:'30px'}}>
        <RangePicker 
          locale={locale} 
          renderExtraFooter={() => '默认allTime'} 
          onChange={this.handleOnChange}
          disabledDate={this.disabledDate}
        ></RangePicker>
      </Space>
    );
  }
}

const mapStateToProps = (state) => ({equip:state.equipmentPage.equip});
const mapDispatchToProps = dispatch => {
  return {
    getCurve: dispatch.equipmentPage.getCurve,
    getAverageRate: dispatch.equipmentPage.getAverageRate,
    setEquip: dispatch.equipmentPage.setState
  }
};
export default connect( 
    mapStateToProps,
    mapDispatchToProps
)(withRouter(CurveDatePicker));